package com.sci.web.controller.admin.v2;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSONObject;
import com.sci.web.business.gateway.UserBusiness;
import com.sci.web.controller.BaseController;
import com.sci.web.model.genmodel.User;
import com.sci.web.util.StringUtil;

public class UserController extends BaseController {
	
	
	
	private UserBusiness userBusiness= new UserBusiness();
	
	
/*	public void login(){
		Map<String , Object> map = new HashMap<String , Object>();
		String reqStr = getPara("reqStr");
		
		Map<String , String> parseObject =(Map<String , String>) JSONObject.parseObject(reqStr , Map.class);
		String pwd = parseObject.get("pwd");
		String name = parseObject.get("name");
		if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(pwd)){
			User user = userBusiness.getUserByNameAndPwd(name.trim(), pwd.trim());
			if(user!=null){
				String bacRoleNo = user.getBacRoleNo();
				if(StringUtil.isNotEmpty(bacRoleNo)){
					map.put("id", user.getSerialId());
					success(map);
				}else{
					map.put("msg", "该用户尚未配置角色,请联系管理员!");
					error(map);
				}
			}else{
				map.put("msg", "该用户不存在,请联系管理员!");
				error(map);
			}
		}
	}
	*/
	
	
	public void login(){
		Map<String , Object> map = new HashMap<String , Object>();
		String name = getPara("name");
		String pwd = getPara("pwd");
		if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(pwd)){
			User user = userBusiness.getUserByNameAndPwd(name.trim(), pwd.trim());
			if(user!=null){
				String bacRoleNo = user.getBacRoleNo();
				if(StringUtil.isNotEmpty(bacRoleNo)){
					getSession().setAttribute("user", user);
					
					redirect("/v2/admin/toIndex");
					
				}else{
					setAttr("msg", "该用户尚未配置角色,请联系管理员!");
					render("login.jsp");
				}
			}else{
				setAttr("msg", "该用户不存在,请联系管理员!");
				render("login.jsp");
			}
		}
	}
	
	
	
	
	
	public void loginout(){
		User user = super.getSessionByUser();
	
		if(user!=null){
			HttpSession session = getRequest().getSession();
			session.removeAttribute("user");
		}
		redirect("/v2");
	}
	
	
	
	
	public void register(){
		String name = getPara("name");
		String pwd = getPara("pwd");
		
	}

}
